﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
using System.Linq;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    //
    public class JLTEK03DOCData : BaseFunction
    {

        public ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }
        SETINTEXDB INTEXDB = new SETINTEXDB();
        public JLTEK03DOCData()
            : base()
        {

        }
        public JLTEK03DOCData(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {
            
        }
        public JLTEK03DOCData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {

        }
        public DataSet LoadSupplier()
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataRow dwData = INTEXDB.LIEFDAT.NewLIEFDATRow();
            dwData["LSMANDANT"] = "00";
            SResult = INTEXDBC.QueryLIEFDAT(dwData, 6);
            SReturn.Merge(SResult);
            return SReturn;
        }
        public DataSet GetOrderBySupplier(DataRow dwInput)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataRow dwData = INTEXDB.EKKOPF.NewRow();
            dwData["EKKMANDANT"] = "00";
            dwData["EKKLIEFNR"] =dwInput["LSLIEFNR"].ToString();
            SResult = INTEXDBC.QueryEKKOPF(dwData, 2);
            SReturn.Merge(SResult);
            return SReturn;
        }
        public DataSet BuildData(DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            try
            {
                Result = INTEXDBC.QueryEKKOPF(dwInput);
                Return.Merge(Result);
                DataRow dwTemp = null;
                #region=======Order======
                foreach (DataRow row in Return.Tables["EKKOPF"].Rows)
                {
                    dwTemp = INTEXDB.EKKOPF.NewRow();
                    dwTemp["EKKMANDANT"] = row["EKKMANDANT"];
                    dwTemp["EKKAUFKRS"] = row["EKKAUFKRS"];
                    dwTemp["EKKAUFLFD"] = row["EKKAUFLFD"];
                    Result = INTEXDBC.QueryLIEFDAT(dwTemp, 7);
                    Result.Tables[0].TableName = "LIEF";
                    Return.Merge(Result);
                    dwTemp["EKKMANDANT"] = row["EKKMANDANT"];
                    dwTemp["EKKAUFKRS"] = row["EKKAUFKRS"];
                    dwTemp["EKKAUFLFD"] = row["EKKAUFLFD"];
                    Result = INTEXDBC.QueryLIEFKO(dwTemp, 5);
                    Return.Merge(Result);
                    foreach (DataRow rx in Result.Tables[0].Rows)
                    {
                        dwTemp = INTEXDB.ZABED.NewRow();
                        dwTemp["ZABMANDANT"] = rx["LSKMANDANT"];
                        dwTemp["ZABNR"] = rx["LSKZAHLBED"];
                        Result = INTEXDBC.QueryZABED(dwTemp, 1);
                        Return.Merge(Result);
                        dwTemp = INTEXDB.TXTIND.NewRow();
                        dwTemp["TXTIMANDANT"] = rx["LSKMANDANT"];
                        dwTemp["TXTITXTART"] = "ZAB";
                        dwTemp["TXTISIND"] = Helper.Left(rx["LSKZAHLBED"].ToString() + "V                                                                                       ", 60);
                        Result = INTEXDBC.QueryTXTKON(dwTemp, 1);
                        dwTemp = INTEXDB.ICC_TXTKON.NewRow();
                        Result = Helper.ConvertTXT(Result.Tables["TXTKON"], dwTemp);
                        Return.Merge(Result);
                    }
                    dwTemp = INTEXDB.ICC_EKPOS.NewRow();
                    dwTemp["EKPMANDANT"] = row["EKKMANDANT"];
                    dwTemp["EKPAUFKRS"] = row["EKKAUFKRS"];
                    dwTemp["EKPAUFLFD"] = row["EKKAUFLFD"];
                    Result = INTEXDBC.QueryEKPOS(dwTemp, 2);
                    Result.Tables[0].TableName = "ICC_EKPOS";
                    Return.Merge(Result);
                    Result = INTEXDBC.QueryGSDAT(dwTemp, 2);
                    Return.Merge(Result);
                    Result = INTEXDBC.QueryGSCOLOR(dwTemp, 3);
                    Return.Merge(Result);
                    Result = INTEXDBC.QueryMSSTAMM(dwTemp, 2);
                    Return.Merge(Result);
                    Result = INTEXDBC.QueryQPPROF(dwTemp, 2);
                    Return.Merge(Result);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
       

    }
}